using System;
using System.Drawing;
using Diagram;
using Diagram.Model;
using Diagram.View;
using PetriDiagram.Model;
using PetriDiagram.Shapes;
using Diagram.Commands;
using PetriDiagram.Commands;

namespace PetriDiagram
{
    [Serializable]
    public class PetriDocument : Document
    {
        private Diagram.View.Diagram diagram;

        public PetriDocument()
        {
            ShapeFactory.AssociateDefaultShape( new Transition( PetriModel ), new TransitionShape() );
            ShapeFactory.AssociateDefaultShape( new Place( PetriModel ), new PlaceShape() );
            ShapeFactory.AssociateDefaultShape( new PetriNetRelation( PetriModel ), new PetriNetConnectionShape() );
            ShapeFactory.AssociateDefaultShape( new InhibitorArc( PetriModel ), new InhibitorShape() );

            CommandManager<Shape>.Instance.RegisterCommand( new EditNameCommand() );
            CommandManager<Shape>.Instance.RegisterCommand( new EditWeightCommand() );
        }

        public Diagram.View.Diagram Diagram
        {
            get
            {
                if(diagram == null)
                {
                    diagram = new NetDiagram( PetriModel, ShapeFactory, new Size( 2000, 2000 ) );
                }
                return diagram;
            }
        }

        protected override EntityManager NewEntityManager()
        {
            return new PetriNetModel();
        }

        public PetriNetModel PetriModel
        {
            get
            {
                return EntityManager as PetriNetModel; 
            }
        }
    }
}
